// 程序入口
import LYStage = Laya.Stage;
import LYLoader = Laya.Loader;
import LYHANDLER = Laya.Handler;
import FGROOT = fairygui.GRoot;
import FGOBJ = fairygui.GObject;
import FGCOM = fairygui.GComponent;
import FUI = fairygui.UIPackage;
class ComChannel extends FGCOM {
    constructor(com: FGCOM) {
        super();
        Object.getOwnPropertyNames(com).forEach(name => { this[name] = com[name]; });
    }
    get value(): number[] {
        const val = [];
        for (let i = 1; i < 6; i++) {
            val.push(Number(this.getChild(`n${i}`).asTextInput.text));
        }
        return val;
    }
}
class GameMain {
    constructor() {
        Laya.init(750, 1334, Laya.WebGL);
            laya.utils.Stat.show(0, 0);
            // 设置适配模式
            Laya.stage.scaleMode = LYStage.SCALE_SHOWALL; // LYStage.SCALE_EXACTFIT;
            Laya.stage.alignH = LYStage.ALIGN_MIDDLE;
            Laya.stage.alignV = LYStage.ALIGN_TOP;
            // 设置横竖屏
            Laya.stage.screenMode = 'none';
            // 加载资源
            Laya.loader.load([{url: 'res/Package1.bin', type: LYLoader.BUFFER},
                                {url: 'res/Package1@atlas0.jpg', type: LYLoader.IMAGE}],
                                LYHANDLER.create(this, this.onLoaded));
    }
    private onLoaded() {
        Laya.stage.addChild(fairygui.GRoot.inst.displayObject);
        FUI.addPackage('res/Package1', LYLoader.getRes('res/Package1.bin'));
        const viewMain = FUI.createObject('Package1', 'viewMain').asCom;
        const chR = new ComChannel(viewMain.getChild('chR').asLabel);
        const chG = new ComChannel(viewMain.getChild('chG').asLabel);
        const chB = new ComChannel(viewMain.getChild('chB').asLabel);
        const chA = new ComChannel(viewMain.getChild('chA').asLabel);
        FGROOT.inst.addChild(viewMain);
        viewMain.getChild('btnApply').asRichTextField.onClick(this, () => {
            const val = [];
            val.push(chR.value.toString());
            val.push(chG.value.toString());
            val.push(chB.value.toString());
            val.push(chA.value.toString());
            const filter = new Laya.ColorFilter(val.toString().split(','));
            viewMain.getChild('n0').displayObject.filters = [filter];
        });
    }
}
new GameMain();